#!/usr/bin/env python3

import sys

if len(sys.argv) != 2:
	print("Usage: stdoutbytes BYTEVALUE", file=sys.stderr)
	sys.exit(1)
try:
	bval = int(sys.argv[1], 0)
	if not (0 <= bval <= 0xFF):
		raise ValueError
except ValueError:
	print("Invalid BYTEVALUE.", file=sys.stderr)
	sys.exit(1)

b = bytes((bval,)) * 2**20
write = sys.stdout.buffer.write
try:
	while True:
		write(b)
except (BrokenPipeError, KeyboardInterrupt) as e:
	sys.exit(0)
except Exception as e:
	print("Exception: %s" % str(e), file=sys.stderr)
sys.exit(1)
